package org.example.paixu;

import java.util.Arrays;
//-------冒泡排序-------
//已近放入git仓库
public class Bubble {
    public static void exch(Comparable[] v,int a,int b){
        Comparable x;
        x=v[a];
        v[a] = v[b];
        v[b] = x;
    }
    public static boolean greater(Comparable v, Comparable w){
        return v.compareTo(w)>0;
    }

    public static void sort(Comparable[] v){
        for(int i=v.length-1;i>0;i--){
            for (int j =0;j<i;j++){
                if(greater(v[j],v[j+1])){
                    exch(v,j,j+1);
                }
            }
        }
    }

    public static void main(String[] args) {
        Integer[] a = {6,2,4,1,1,7,9};
        Bubble.sort(a);
        System.out.println(Arrays.toString(a));

    }
}
